package com.lineage.data.npc.quest;

import com.lineage.data.cmd.CreateNewItem;
import com.lineage.data.executor.NpcExecutor;
import com.lineage.data.quest.CKEWLv50_1;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.templates.L1QuestUser;
import com.lineage.server.world.WorldQuest;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_RottingCorpse extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_RottingCorpse.class);
  
  public static NpcExecutor get() {
    return new Npc_RottingCorpse();
  }
  
  public int type() {
    return 1;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (!pc.isInParty())
        return; 
      int i = 0;
      Iterator<L1PcInstance> iterator = pc.getParty().partyUsers().values().iterator();
      while (iterator.hasNext()) {
        L1PcInstance otherPc = iterator.next();
        if (otherPc.isCrown()) {
          i++;
          continue;
        } 
        if (otherPc.isKnight()) {
          i += 2;
          continue;
        } 
        if (otherPc.isElf()) {
          i += 4;
          continue;
        } 
        if (!otherPc.isWizard())
          continue; 
        i += 8;
      } 
      if (i != 15) {
        L1QuestUser quest = WorldQuest.get().get(pc.get_showId());
        quest.endQuest();
        return;
      } 
      if (pc.isCrown()) {
        if (pc.getQuest().isStart(CKEWLv50_1.QUEST.get_id()) && !pc.getInventory().checkItem(49239))
          CreateNewItem.getQuestItem((L1Character)pc, npc, 49239, 1L); 
      } else if (pc.isKnight()) {
        if (pc.getQuest().isStart(CKEWLv50_1.QUEST.get_id()) && !pc.getInventory().checkItem(49239))
          CreateNewItem.getQuestItem((L1Character)pc, npc, 49239, 1L); 
      } else if (pc.isElf()) {
        if (pc.getQuest().isStart(CKEWLv50_1.QUEST.get_id()) && !pc.getInventory().checkItem(49239))
          CreateNewItem.getQuestItem((L1Character)pc, npc, 49239, 1L); 
      } else if (pc.isWizard()) {
        if (pc.getQuest().isStart(CKEWLv50_1.QUEST.get_id()) && !pc.getInventory().checkItem(49239))
          CreateNewItem.getQuestItem((L1Character)pc, npc, 49239, 1L); 
      } else if (!pc.isDarkelf() && !pc.isDragonKnight()) {
        pc.isIllusionist();
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
